/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.colswe.solestac.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Operador
 */
@Entity
@Table(name = "STUDENT")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Student.findAll", query = "SELECT s FROM Student s"),
    @NamedQuery(name = "Student.findById", query = "SELECT s FROM Student s WHERE s.id = :id"),
    @NamedQuery(name = "Student.findByName", query = "SELECT s FROM Student s WHERE s.name = :name"),
    @NamedQuery(name = "Student.findByLastName", query = "SELECT s FROM Student s WHERE s.lastName = :lastName"),
    @NamedQuery(name = "Student.findByDocument", query = "SELECT s FROM Student s WHERE s.document = :document"),
    @NamedQuery(name = "Student.findByCode", query = "SELECT s FROM Student s WHERE s.code = :code") })
public class Student implements Serializable {
    
    /**Version of the Serializable interface.
     */
    private static final long serialVersionUID = 1L;
    /**Id from the Student.
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID")
    private Long id;
    /**Name from the Student.
     */
    @Column(name = "NAME")
    private String name;
    /**Last Name from the Student.
     */
    @Column(name = "LAST_NAME")
    private String lastName;
    /**Document from the Student.
     */
    @Column(name = "DOCUMENT")
    private String document;
    /**Code from the Student.
     */
    @Column(name = "CODE")
    private String code;
    /**Program from the Student.
     */
    @JoinColumn(name = "PROGRAM_ID", referencedColumnName = "ID")
    @ManyToOne
    private Program programId;
    /**Request List from the Student.
     */
    @OneToMany(mappedBy = "studentId")
    private List<Request> requestList;

    /**Default constructor.
     */
    public Student() {
        requestList = new ArrayList<Request>();
    }

    /**Constructor using the Id.
     * @param newId The new value 
     */
    public Student(final Long newId) {
        this.id = newId;
    }

    /**Getter for Id.
     * @return  The ID value
     */
    public Long getId() {
        return id;
    }

    /**Setter for Id.
     * @param newId The new value 
     */
    public void setId(final Long newId) {
        this.id = newId;
    }

    /**Getter for Name.
     * @return The Name value
     */
    public String getName() {
        return name;
    }

    /** Setter for Name.
     * @param newName The new value
     */
    public void setName(final String newName) {
        this.name = newName;
    }

    /**Getter for Last Name.
     * @return The LastName value
     */
    public String getLastName() {
        return lastName;
    }

    /**Setter for Last Name.
     * @param newLastName The new value
     */
    public void setLastName(final String newLastName) {
        this.lastName = newLastName;
    }

    /**Getter for Document.
     * @return The Document value
     */
    public String getDocument() {
        return document;
    }

    /**Setter for Document.
     * @param newDocument The new value
     */
    public void setDocument(final String newDocument) {
        this.document = newDocument;
    }

    /**Getter for Code.
     * @return The Code value.
     */
    public String getCode() {
        return code;
    }

    /**
     * Setter for Code.
     * @param newCode The new value
     */
    public void setCode(final String newCode) {
        this.code = newCode;
    }

    /**Getter for Program.
     * @return The Program value.
     */
    public Program getProgramId() {
        return programId;
    }

    /**Setter for Program.
     * @param newProgramId The new Program.
     */
    public void setProgramId(final Program newProgramId) {
        this.programId = newProgramId;
    }

    /**Getter for Request List.
     * @return The RequestList
     */
    @XmlTransient
    public List<Request> getRequestList() {
        return requestList;
    }

    /**Setter for Request List.
     * @param newRequestList The new RequestList.
     */
    public void setRequestList(final List<Request> newRequestList) {
        this.requestList = newRequestList;
    }

    /**Assignment of the hashcode.
     * @return The hash
     */
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    /**Compare two Student objects based on the Id.
     * @param object The object to compare
     * @return The result of the comparison.
     */
    @Override
    public boolean equals(final Object object) {
        if (!(object instanceof Student)) {
            return false;
        }
        Student other = (Student) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    /**Convert to string using the Id.
     * @return The string
     */
    @Override
    public String toString() {
        return "org.colswe.solestac.entity.Student[ id=" + id + " ]";
    }   
}
